package bank
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import global.GameState;
	
	import model.load.XmlLoadMessage;
	
	import utils.ColorTool;
	import utils.DisplayTool;
	
	import view.LabelText;
	import view.components.LabelButton;
	import view.components.list.TileList;
	
	public class SearchResult extends Sprite
	{
		private var list:TileList;
		private var currentMsg:XmlLoadMessage;
		
		public function SearchResult()
		{
			initBg();
			initList();
		}
		
		private function initBg():void
		{
			ColorTool.drawPanelBg(this.graphics,150,250);
			ColorTool.dropShadow(this);
			
			addChild(new LabelText(5,3,100,20,"搜索结果:"));
			addChild(new LabelButton(this.width - 24,3,0,onBut,"panel_close"));
		}
		
		private function onBut(event:MouseEvent):void
		{
			DisplayTool.removeChild(this.parent,this);
			list.removeAll();
		}
		
		private function initList():void
		{
			list = new TileList(140,223,new ItemBank());
			list.x = 5;
			list.y = 23;
			addChild(list);
		}
		
		public function seach(key:String):void
		{
			if (currentMsg)
			{
				currentMsg.cancel();
			}
			
			var msg:XmlLoadMessage = new XmlLoadMessage(onSeachBack);
			msg.isImmediate = true;
			msg.url = GameState.getServerLink() + "54&key=" + GameState.snsKey + "&formula=" + key;
			msg.send();
			
			currentMsg = msg;
		}
		
		private function onSeachBack(data:XML,id:int):void
		{
			list.removeAll();
			var xml:XML;
			for each (xml in data.children())
			{
				xml.@steal = "0";
				list.addItem(xml); 
			}
		}
		
		public function isAllAlphabet(content:String):Boolean
		{
			for (var i:int=0; i<content.length; i++)
			{
				var c:Number = content.charCodeAt(i);
				if ((c >= 0x4e00)&&(c <= 0x9fbb))
				{
					return false;			
				}
			}
			return true;
		}
	}
}